﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MercuryFE
{
    /// <summary>
    /// Interaction logic for PopupMenu.xaml
    /// </summary>
    public partial class PopupMenu : MyWindow
    {
        private int _sourceKey;

        public PopupMenu(int sourceKey)
        {
            InitializeComponent();
            _sourceKey = sourceKey;
            populateMenu();
        }


        private void populateMenu()
        {
            lbMenu.Items.Add("Add to end of queue");
            lbMenu.Items.Add("Add to top of queue");
            lbMenu.Items.Add("Replace queue");

            lbMenu.SelectedIndex = 0;
        }

        private void handleSelect()
        {
            string selection = (string)lbMenu.SelectedItem;

            if (selection == "Add to end of queue")
            {
                App.__soundHandler.addCollectionToQueue(_sourceKey, SoundHandler.AddToQueueType.Bottom);
            }
            else if (selection == "Add to top of queue")
            {
                App.__soundHandler.addCollectionToQueue(_sourceKey, SoundHandler.AddToQueueType.Top);
            }
            else
            {
                App.__soundHandler.addCollectionToQueue(_sourceKey, SoundHandler.AddToQueueType.Replace);
            }

            this.Close();
        }

        public override void DoNavigation(NavigationHook.NavigationTask navigationTask, bool normalSpeed)
        {

            int maxIndex = lbMenu.Items.Count - 1;
            int minIndex = 0;

            switch (navigationTask)
            {
                case NavigationHook.NavigationTask.Left:

                    break;
                case NavigationHook.NavigationTask.Right:

                    break;
                case NavigationHook.NavigationTask.Up:
                    if (lbMenu.SelectedIndex > minIndex)
                        lbMenu.SelectedIndex--;
                    else
                        lbMenu.SelectedIndex = maxIndex;
                    break;
                case NavigationHook.NavigationTask.Down:
                    if (lbMenu.SelectedIndex == maxIndex)
                        lbMenu.SelectedIndex = minIndex;
                    else
                        lbMenu.SelectedIndex++;
                    break;
                case NavigationHook.NavigationTask.Select:
                    handleSelect();
                    break;
                case NavigationHook.NavigationTask.Back:
                    this.Close();
                    break;
                case NavigationHook.NavigationTask.Pause:
                    break;

            }

        }
    }
}
